package com.txw.javaCore.server.controller;

import com.txw.javaCore.api.response.BaseResponse;
import com.txw.javaCore.api.response.StatusCode;
import com.txw.javaCore.server.service.IndexDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PROJECT_NAME: JavaCoreB2
 * @DESCRIPTION: 基于线程池+FutureTask实现 多任务多线程异步执行
 * @Author: 涂玄武
 * @DATE: 2021/2/3 10:52
 */
@RestController
@RequestMapping("index")
public class IndexDataController extends BaseController{

    @Autowired
    private IndexDataService dataService;

    /**
     * 获取首页数据-方式一(传统的同步流的方式)
     * @return
     */
    @RequestMapping("data/V1")
    public BaseResponse indexDataV1(){
        BaseResponse response =  new BaseResponse(StatusCode.Success);
        try {
            response.setData(dataService.getIndexDataV1());
        }catch (Exception e){
            response = new BaseResponse(StatusCode.Fail.getCode(),e.getMessage());
        }
        return response;
    }

    /**
     * 获取首页数据-方式二
     * @return
     */
    @RequestMapping("data/V2")
    public BaseResponse indexDataV2(){
        BaseResponse response=new BaseResponse(StatusCode.Success);
        try {
            response.setData(dataService.getIndexDataV2());

        }catch (Exception e){
            response=new BaseResponse(StatusCode.Fail.getCode(),e.getMessage());
        }
        return response;
    }
}
